﻿@{
    ViewBag.Title = "ShowWorkShop";
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 引入 layui.css -->
    <link href="//unpkg.com/layui@2.9.17/dist/css/layui.css" rel="stylesheet">
</head>
<body>
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">车间编码</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" id="WorkShopCode" lay-verify="required" placeholder="请输入车间编码" autocomplete="off" class="layui-input">
            </div>
            <label class="layui-form-label">车间名称</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" id="WorkShopName" lay-verify="required" placeholder="请输入车间名称" autocomplete="off" class="layui-input">
            </div>
            <button type="button" id="getWorkShop" class="layui-btn layui-bg-blue">搜索</button>
            <button type="reset" id="restWorkShop" class="layui-btn">重置</button>
        </div>
        <button type="button" class="layui-btn layui-btn-primary  layui-bg-blue" lay-on="layui-badge-dot">添加</button>
        <button type="button" class="layui-btn layui-bg-orange" lay-event="upd">修改</button>
        <button type="button" class="layui-btn layui-bg-red"  lay-event="del">删除</button>
        <table class="layui-hide" id="WorkShop" lay-filter="test">
        </table>
        <script type="text/html" id="barDemo">
            <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
        </script>
    </form>

    <!-- 引入 layui.js -->
    <script src="~/libs/jquery/jquery.js"></script>
    <script src="//unpkg.com/layui@2.9.17/dist/layui.js"></script>
   @*  显示 *@
    <script>

        layui.use(['laydate', 'laypage', 'layer', 'table', 'carousel', 'upload', 'element', 'slider'], function () {
            var layer = layui.layer //弹层
                , table = layui.table //表格
                , util = layui.util
                , datas = [];
            var $ = layui.$;
            var form = layui.form;
             //显示
            showWorkShop = function () {
                layui.use(function () {
                    // 创建表格实例
                    table.render({
                        elem: '#WorkShop',
                        url: '/WorkShop/GetWorkShoppService', // 此处为静态模拟数据，实际使用时需换成真实接口
                        where: {
                            WorkShopCode: $("#WorkShopCode").val(),
                            WorkShopName: $("#WorkShopName").val()
                        },
                        cols: [[
<<<<<<< HEAD
                            //{ type: 'checkbox', fixed: 'left' },
=======
                            { type: 'checkbox', fixed: 'left'},
>>>>>>> 352fb028cd5499f06f486d3f1ee77865c7b2241c
                            { field: 'WorkShopCode', title: '车间编码' },
                            { field: 'WorkShopName', title: '车间名称' },
                            { field: 'Area', title: '面积' },
                            { field: 'Charger', title: '负责人' },
                            { field: 'IsEnable', title: '是否启用', templet: function (row) {
                                    return row.IsEnable == "1" ? "是" : "否"
                            } },
                            { field: 'Remark', title: '备注' },
                            { fixed: "right", title: '操作', align: 'center', toolbar: '#barDemo' }
                        ]],
                        done: function () {
                            var id = this.id;
                            table.on('checkbox(test)', function (obj) {
                                datas.push(obj.data);
                            });
                        }
                    });
                });
            }
            //显示
            showWorkShop();
            //查询
            $("#getWorkShop").on("click", function () {
                showWorkShop();
            })
            //重置
            $("#restWorkShop").on("click", function () {
                showWorkShop();
            })

            //添加
            util.on('lay-on', {
                'layui-badge-dot': function () {
                    layer.open({
                        type: 2,
                        area: ['800px','500px'],
                        resize: false,
                        shadeClose: true,
                        title: '添加车间',
<<<<<<< HEAD
                        content: `
                         <form class="layui-form" action="" onsubmit="return false">
                           <div class="layui-form-item">
                              <label class="layui-form-label">车间编码</label>
                           <div class="layui-input-block">
                                <input type="text" name="workShopCode" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                          </div>
                           </div>

                           <div class="layui-form-item">
                               <label class="layui-form-label">车间名称</label>
                                   <div class="layui-input-block">
                                <input type="text" name="workShopName" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                                    </div>
                            </div>

                       
                            <div class="layui-form-item">
                                 <label class="layui-form-label">面积</label>
                             <div class="layui-input-block">
                                  <input type="text" name="area" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                             </div>
                             </div>

                                    <div class="layui-form-item">
                                         <label class="layui-form-label">负责人</label>
                                     <div class="layui-input-block">
                                         <input type="text" name="charger" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                                 </div>
                                 </div>

                                 <div class="layui-form-item">
                                      <label class="layui-form-label">是否启用</label>
                                 <div class="layui-input-block">
                                      <input type="radio" name="isEnable" value="true" title="是" checked>
                                      <input type="radio" name="isEnable" value="false" title="否">
                                 </div>
                                 </div>

                                  <div class="layui-form-item layui-form-text">
                                        <label class="layui-form-label">备注</label>
                                        <div class="layui-input-block">
                                                  <textarea placeholder="请输入内容" class="layui-textarea" name="remark"></textarea>
                                        </div>
                                      </div>

                                      <div class="layui-form-item">
                                        <div class="layui-input-block">
                                          <button type="submit" class="layui-btn" lay-submit lay-filter="addworkShop">立即提交</button>
                                          <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                        </div>
                                      </div>
                                    </form>
                                            `,
                        success: function () {
                            // 对弹层中的表单进行初始化渲染
                            form.render();
                            // 表单提交事件
                            form.on('submit(addworkShop)', function (data) {
                                var field = data.field; // 获取表单字段值
                                // 此处可执行 Ajax 等操作
                                console.log(field)
                                $.ajax({
                                    url: "/WorkShop/AddWorkShoppService",
                                    type: "get",
                                    async: true,
                                    data: data.field,
                                    contentType: "application/json",
                                    success: res => {
                                        if (res != null) {
                                            alert("添加成功")
                                            //关闭弹出层
                                            layer.closeAll();
                                            //刷新表格
                                             showWorkShop();
                                            return;
=======
                        content: `https://localhost:44311/WorkShop/AddWorkShop`,
                        btn:['确定','取消'],
                        yes: function (index, layero) {
                            var data = layer.getChildFrame('body', index).find('form').serialize();
                            console.log(data);
                                    $.ajax({
                                        url: "/WorkShop/AddWorkShoppService",
                                        type: "get",
                                        async: true,
                                        data: data,
                                        contentType: "application/json",
                                        success: res => {
                                            if (res != null) {
                                                alert("添加成功")
                                                //关闭弹出层
                                                layer.closeAll();
                                                //刷新表格
                                                showWorkShop();
                                                return;
                                            }
                                            else {
                                                console.log(res.code)
                                                alert("添加失败")
                                            }
>>>>>>> 352fb028cd5499f06f486d3f1ee77865c7b2241c
                                        }
                                    });
                                    return false; // 阻止默认 form 跳转
                                }
                        })
                        }
                    });

            //删除
            table.on('tool(test)', function (obj) {
                var data = obj.data//获取当前数据
                    , layEvent = obj.event;//获取lay-event获取对应的值
                if (layEvent == 'delete') {
                    layer.confirm('确定删除当前车间吗？', function (index) {
                        $.ajax({
                            url: "/WorkShop/DelWorkShopp?id=" + data.Id,
                            type: "get",
                            success:res=>{
                                if(res>0)
                                {
                                    alert("删除成功");
                                    obj.del();
                                    layer.close(index);
                                }
                            }
                        }); 
                    })
                }
                //修改
                else if (layEvent == 'edit') {
                    console.log(data.Id)
                    layer.open({
                        type:2,
                        area:['800px','500px'],
                        resize:false,
                        shadeClose:true,
                        title:'修改车间',
                        content: '/WorkShop/GetWorkShop?id=' + data.Id,
                        btn:['确定','取消'],
                        yes:function(index,layero){
                            var data = layer.getChildFrame('body', index).find('form').serialize();
                            console.log(data);
                            $.ajax({
                                url: "/WorkShop/UpdWorkShopBy",
                                type: 'get',
                                contentType: 'application/json',
                                data: data,
                                success: res => {
                                    if (res != null) {
                                        alert("修改成功")
                                        //关闭弹出层
                                        layer.closeAll();
                                        //刷新表格
                                        showWorkShop();
                                        return;
                                    }
                                    else {
                                        console.log(res.code)
                                        alert("修改失败")
                                    }
                                }                                          
                            })
                            return false; // 阻止默认 form 跳转
                        }
                    })
                }
            });

        }); 
    </script>
</body>
</html>